classdef DOSCAR
  %DOSCAR Summary of this class goes here
  %   Detailed explanation goes here
  
   properties
    Header;
    Energies;
    TotalDOS;
    IntDOS;
  end
  
  methods
    function eObj = DOSCAR(header, energies, total_dos, int_dos)
      eObj.Header = header;
      eObj.Energies = energies;
      eObj.TotalDOS = total_dos;
      eObj.IntDOS = int_dos;
    end

  end
  
  
  methods(Static)    
    
    test();
  
    function eObj = read()      
      fid = fopen('DOSCAR', 'r+t');
      ions = fscanf(fid, '%f\n', 4);
      volume = fscanf(fid, '%f\n', 5);
      T = fscanf(fid, '%f\n', 1);
      carString = fscanf(fid, '%s\n', 1);
      header = fscanf(fid, '%s\n', 1);
      numPoints = fscanf(fid, '%f\n', 5);
      
      numEnergies = numPoints(3);
      
      energies = fscanf(fid, '%f\n', numEnergies*3);
          
      dos = reshape(energies, 3, numEnergies);
      energies = dos(1, :);
      total_dos = dos(2, :);
      int_dos = dos(3, :);
      
      siteProjectedDOS = zeros(ions(1), numEnergies, 4);
      for i = 1:ions(1)
        numPoints = fscanf(fid, '%f\n', 5);
        currentSiteProjectedDOS = fscanf(fid, '%f\n', numEnergies*4);
        siteProjectedDOS(i, :, :) = reshape(currentSiteProjectedDOS, 4, numEnergies)';
      end
      
      fclose(fid);
      
      eObj = DOSCAR(header, energies, total_dos, int_dos);
      
    end
  end
  
end

